/**
 * User.js
 *
 * @description :: A model definition represents a database table/collection.
 * @docs        :: https://sailsjs.com/docs/concepts/models-and-orm/models
 */
const dateCheck = require('../common/datetime_check')

module.exports = {
  datastore: 'mysql',
  tableName: 'user',
  primaryKey: 'id',

  attributes: {
    id: {
      columnName: 'user_id',
      type: 'number',
      autoIncrement: true
    },
    userName: {
      columnName:'user_name',
      type:'string',
      required:true,
      allowNull:false
    },
    gender: {
      columnName:'gender',
      type:'number',
      required:true,
      allowNull:false
    },
    birthDay: {
      columnName:'birth_day',
      type:'string',
      required:true,
      allowNull:false,
      custom:function(value){
        return dateCheck.isDate(value)
      }
    },
    career: {
      columnName:'career',
      type:'string',
      required:false,
      allowNull:true,
    },
    // createdAt: {
    //   columnName:'create_time',
    //   type:'string',
    //   columnType: 'datetime',
    //   autoCreatedAt: true,
    //   defaultsTo: () => moment().format("YYYY-MM-DD HH:mm:ss")
    // },
    updatedAt: {
      columnName:'update_time',
      type:'string',
      required:false,
      allowNull:true,
      custom:function(value){
        return dateCheck.isDateTime(value)
      }
    }
  }
};

